package cn.itsource.quartz.service.impl;

import cn.itsource.quartz.jobs.MainJob;
import cn.itsource.quartz.service.IQuartzService;
import cn.itsource.quartz.util.QuartzJobInfo;
import cn.itsource.quartz.util.QuartzUtils;
import org.quartz.Scheduler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
import org.springframework.stereotype.Service;

@Service
public class QuartzServiceImpl implements IQuartzService {
    @Autowired
    private SchedulerFactoryBean factoryBean;
    @Override
    public void addJob(QuartzJobInfo info) {
        Scheduler scheduler = factoryBean.getScheduler();
        //参数直接把info传递进去，里面不仅需要type还是params
        QuartzUtils.addJob(scheduler,info.getJobName(),
                MainJob.class,info,info.getCronj());
    }

    @Override
    public void delJob(String jobName) {
        Scheduler scheduler = factoryBean.getScheduler();
        QuartzUtils.removeJob(scheduler,jobName);

    }
}
